<?php
    include_once ('inc/class/User.class.php');
    include_once ('inc/global/global.inc.php');
    include_once ('inc/code/headIndex.php');
    include_once ('inc/class/Form.class.php');

    include_once ('inc/class/Util.class.php');


    if(isset($_REQUEST['registrati'])){

        $res = User::registra_utente($_POST[nome],$_POST[cognome],$_POST[mail],$_POST[username],$_POST[password],$_POST[telefono],$_POST[cap],$_POST[citta],$_POST[data_nascita],$_POST[indirizzo]);
        if($res)
            echo "<script> alert('Registrato correttamente') </script>";
    }
    if(!isset($utente))
        $utente = new User();
        
    if($_GET["id"] == 1){
        $utente->login_utente($_POST[username],$_POST[password]);
    }
    else if($_GET["action"] == "logout"){
        User::logout();

    }
?>
<div id="Content">
    
    <div id="One">
          <H2>&raquo; Home</H2>
        
          <p>Benvenuto</p>

          <p><a href="register.php">Nuovo utente? Registrati!</a></p>
                    <blockquote>
                    <fieldset>
                    <legend>Login</legend>
                    <?php
                    $formLogin = new Form("index.php?id=1", "POST", "login");

                    $formLogin->open_form();

                    $formLogin->add_input("username", "text", "Username:", "username");
                    $formLogin->add_input("password", "password", "Password:", "password");
                    $formLogin->add_button("submit","login", "Login");

                    $formLogin->close_form();
                    
                    ?>
                    
                    </fieldset>                  
                    
                    </blockquote>
          
    </div>
</div>
</div>

<?php
    include ('inc/code/footer.php');
?>